import { PartialType } from '@nestjs/mapped-types';
import { IsEnum, IsNumber, IsOptional, IsString, Matches } from 'class-validator';
import { CaptchaVerifyEnum } from '@/common/enums';
import { useRegExp } from '@/common/hooks/useRegExp';

export class AuthDto {}

export class EmailCaptchaDto extends PartialType(AuthDto) {
  @Matches(useRegExp('email').regexp, { message: useRegExp('email').msg })
  to: string;

  @IsEnum(CaptchaVerifyEnum)
  type: CaptchaVerifyEnum;
}

export class GraphicsCaptchaDto extends PartialType(AuthDto) {
  @IsEnum(CaptchaVerifyEnum)
  type: CaptchaVerifyEnum;
}

export class ParseTokenDto extends PartialType(AuthDto) {
  @IsString()
  token: string;
}

export class CreateTokenDto extends PartialType(AuthDto) {
  @IsNumber()
  id: number;

  @IsString()
  @IsOptional()
  username?: string;

  @IsString({ each: true })
  @IsOptional()
  roles?: string[];
}

export class VerifyTokenDto extends PartialType(AuthDto) {
  @IsString()
  access_token: string;

  @IsString()
  refresh_token: string;
}
